package com.yuanyu.server.impl;

import com.yuanyu.common.util.AssertUtil;
import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.mapper.mysqlMapper.MainTable_Mapper;
import com.yuanyu.mapper.mysqlMapper.Multistage_dry_pump_assembly_records.Multistage_dry_pump_assembly_records_1_Mapper;
import com.yuanyu.mapper.mysqlMapper.Multistage_dry_pump_assembly_records.Multistage_dry_pump_assembly_records_Mapper;
import com.yuanyu.model.dto.Multistage_dry_pump_assembly_recordsDTO;
import com.yuanyu.model.entity.Multistage_dry_pump_assembly_records.Multistage_dry_pump_assembly_records;
import com.yuanyu.model.entity.Multistage_dry_pump_assembly_records.Multistage_dry_pump_assembly_records_1;
import com.yuanyu.model.vo.Multistage_dry_pump_assembly_recordsVO;
import com.yuanyu.server.ITestPart6Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@Transactional
public class TestPart6ServerImpl implements ITestPart6Server {
    @Autowired
    private Multistage_dry_pump_assembly_records_Mapper multistageDryPumpAssemblyRecordsMapper;
    @Autowired
    private Multistage_dry_pump_assembly_records_1_Mapper multistageDryPumpAssemblyRecords1Mapper;
    @Autowired
    private MainTable_Mapper mainTableMapper;

    @Override
    public String test() {
        return "测试成功";
    }

    @Override
    public String test6(Multistage_dry_pump_assembly_recordsVO multistageDryPumpAssemblyRecordsVO) {
        Multistage_dry_pump_assembly_records_1 test = multistageDryPumpAssemblyRecords1Mapper.selTable1(multistageDryPumpAssemblyRecordsVO.getInput_Case());
        AssertUtil.isNull(test,"Case已存在,如需修改内容请前往后台修改");

        Multistage_dry_pump_assembly_records multistageDryPumpAssemblyRecords = new Multistage_dry_pump_assembly_records();
        Multistage_dry_pump_assembly_records_1 multistageDryPumpAssemblyRecords1 = new Multistage_dry_pump_assembly_records_1();

        CopyUtil.copyClass(multistageDryPumpAssemblyRecordsVO,multistageDryPumpAssemblyRecords);
        multistageDryPumpAssemblyRecords.setCreatedAt(LocalDateTime.now());
        multistageDryPumpAssemblyRecords.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(multistageDryPumpAssemblyRecordsVO,multistageDryPumpAssemblyRecords1);

        System.out.println(multistageDryPumpAssemblyRecords);
        System.out.println(multistageDryPumpAssemblyRecords1);

        int i = multistageDryPumpAssemblyRecordsMapper.addTableTime(multistageDryPumpAssemblyRecords);
        int i1 = multistageDryPumpAssemblyRecords1Mapper.addTable1(multistageDryPumpAssemblyRecords1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"添加数据出现异常,请检查");
        mainTableMapper.updateByCaseFormStartTime(multistageDryPumpAssemblyRecordsVO.getInput_Case());
        return "添加成功";
    }

    @Override
    public String updateTable6(Multistage_dry_pump_assembly_recordsVO multistageDryPumpAssemblyRecordsVO) {
        Multistage_dry_pump_assembly_records multistageDryPumpAssemblyRecords = new Multistage_dry_pump_assembly_records();
        Multistage_dry_pump_assembly_records_1 multistageDryPumpAssemblyRecords1 = new Multistage_dry_pump_assembly_records_1();

        CopyUtil.copyClass(multistageDryPumpAssemblyRecordsVO,multistageDryPumpAssemblyRecords);
        multistageDryPumpAssemblyRecords.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(multistageDryPumpAssemblyRecordsVO,multistageDryPumpAssemblyRecords1);

        int i = multistageDryPumpAssemblyRecordsMapper.updateTableTime(multistageDryPumpAssemblyRecords);
        int i1 = multistageDryPumpAssemblyRecords1Mapper.updateTable1(multistageDryPumpAssemblyRecords1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"表6修改数据出现异常,请检查");
        return "修改成功";
    }

    @Override
    public Multistage_dry_pump_assembly_recordsDTO getTest6(String Case) {
        Multistage_dry_pump_assembly_records multistageDryPumpAssemblyRecords = multistageDryPumpAssemblyRecordsMapper.selTableTime(Case);
        if (multistageDryPumpAssemblyRecords == null)return null;
        Multistage_dry_pump_assembly_records_1 multistageDryPumpAssemblyRecords1 = multistageDryPumpAssemblyRecords1Mapper.selTable1(Case);
        Multistage_dry_pump_assembly_recordsDTO multistageDryPumpAssemblyRecordsDTO = new Multistage_dry_pump_assembly_recordsDTO();
        CopyUtil.copyClass(multistageDryPumpAssemblyRecords,multistageDryPumpAssemblyRecordsDTO);
        CopyUtil.copyClass(multistageDryPumpAssemblyRecords1,multistageDryPumpAssemblyRecordsDTO);
        return multistageDryPumpAssemblyRecordsDTO;
    }
}
